package com.nbjtjc.safe.api.danger;

import com.nbjtjc.common.validator.ValidatorUtils;
import com.nbjtjc.common.validator.group.DeleteGroup;
import com.nbjtjc.common.validator.group.UpdateGroup;
import com.nbjtjc.safe.annotation.SysLog;
import com.nbjtjc.safe.bean.Result;
import com.nbjtjc.safe.model.danger.DangerInspect;
import com.nbjtjc.safe.model.danger.DangerSafePlan;
import com.nbjtjc.safe.model.danger.SafeDangerInspectLabel;
import com.nbjtjc.safe.service.danger.DangerSafePlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @auther guqianbin
 * @date 2018/4/10 10:00
 * 隐患检查年度计划
 **/
@RestController
@RequestMapping("/danger/safePlan")
@CrossOrigin("*")
public class DangerSafePlanController {

    @Autowired
    private DangerSafePlanService dangerSafePlanService;

    @SysLog("添加隐患检查计划")
    @RequestMapping(value = "/add", method = {RequestMethod.POST})
    public Result add(@RequestBody DangerSafePlan dangerSafePlan) {
        ValidatorUtils.validateEntity(dangerSafePlan);
        Result result = dangerSafePlanService.add(dangerSafePlan);
        return result;
    }

    @SysLog("删除隐患检查计划")
    @RequestMapping(value = "/delete", method = {RequestMethod.POST})
    public Result delete(@RequestBody DangerSafePlan dangerSafePlan) {
        ValidatorUtils.validateEntity(dangerSafePlan, UpdateGroup.class);
        Result result = dangerSafePlanService.delete(dangerSafePlan);
        return result;
    }

    @SysLog("更新隐患检查计划表")
    @RequestMapping(value = "/update", method = {RequestMethod.POST})
    public Result update(@RequestBody DangerSafePlan dangerSafePlan) {
        ValidatorUtils.validateEntity(dangerSafePlan, UpdateGroup.class);
        Result result = dangerSafePlanService.update(dangerSafePlan);
        return result;
    }

    @RequestMapping(value = "/find", method = {RequestMethod.POST})
    public Result find(@RequestBody DangerSafePlan dangerSafePlan) {
        Result result = dangerSafePlanService.find(dangerSafePlan);
        return result;
    }

    @RequestMapping(value = "/detail", method = {RequestMethod.POST})
    public Result detail(DangerSafePlan dangerSafePlan) {
        Result result = new Result();
        result.setData(dangerSafePlanService.getDetail(dangerSafePlan));
        return result;
    }
}
